home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / cardpkg_1.3.lha / CardPkg / Hello_H.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  4.5 KB  |  161 lines

  1. /************************************************************
  2.  
  3.     TML's C Language Card Image Package  v1.1
  4.  
  5.     January, 1993
  6.     Todd M. Lewis             (919) 776-7386
  7.     2601 Piedmont Drive
  8.     Sanford, NC  27330-9437
  9.     USA
  10. ************************************************************/
  11. #include <stdlib.h>
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/intuitionbase.h>
  15.  
  16. #ifdef AZTEC_C
  17.   #include <functions.h>
  18.   #define __far
  19. #endif
  20. #ifdef __SASC
  21.   #include <clib/alib_protos.h>
  22.   #include <clib/intuition_protos.h>
  23.   #include <clib/graphics_protos.h>
  24.   #include <clib/dos_protos.h>
  25.   #include <clib/exec_protos.h>
  26. #endif
  27.  
  28. #include "CardHImages.h"
  29. #include "Cards.h"
  30.  
  31. extern UWORD       RangeRand( ULONG );
  32. extern ULONG __far RangeSeed;
  33.  
  34. struct IntuitionBase *IntuitionBase;
  35. struct GfxBase       *GfxBase;
  36.  
  37. #define INTUITION_REV 28
  38. #define GRAPHICS_REV  28
  39.  
  40. struct Window *Window;
  41. struct NewWindow newwindow =
  42.   {
  43.         20,13,   /* window XY origin relative to TopLeft of screen */
  44.         569,158, /* window width and height */
  45.         0,1,     /* detail and block pens */
  46.         CLOSEWINDOW,    /* IDCMP flags */
  47.         WINDOWDRAG  | WINDOWDEPTH |
  48.         WINDOWCLOSE | ACTIVATE    | NOCAREREFRESH,  /* other window flags */
  49.         NULL,   /* first gadget in gadget list */
  50.         NULL,   /* custom CHECKMARK imagery */
  51.         (UBYTE *)" Testing Card Images ",       /* window title */
  52.         NULL,   /* custom screen pointer */
  53.         NULL,   /* custom bitmap */
  54.         5,5,    /* minimum width and height */
  55.         0xffff,0xffff,  /* maximum width and height */
  56.         WBENCHSCREEN    /* destination screen type */
  57.   };
  58.  
  59. CardID_t cards[56]; /* 52 "normal" and 4 "special" cards */
  60.  
  61. void clear_a_card( int i ) /* Remove a single card. */
  62.   {
  63.     ShowHCard( Window->RPort,
  64.                CARD_NONE,
  65.                Window->BorderLeft + 2 + (i / 7) * (CARD_H_WIDTH +5),
  66.                Window->BorderTop  + 2 + (i % 7) * (CARD_H_HEIGHT+2)
  67.              );
  68.   }
  69.  
  70. void clear_cards( void )  /* Clear all the cards. */
  71.   {
  72.     int i;
  73.     for (i=0; i<56; i++)
  74.       {
  75.         clear_a_card( i );
  76.         Delay( 5L );
  77.       }
  78.   }
  79.  
  80. void show_a_card( int i )  /* Shows a single card ( cards[i] ). */
  81.   {
  82.     ShowHCard( Window->RPort,
  83.                cards[i],
  84.                Window->BorderLeft + 2 + (i / 7) * (CARD_H_WIDTH +5),
  85.                Window->BorderTop  + 2 + (i % 7) * (CARD_H_HEIGHT+2)
  86.              );
  87.   }
  88.  
  89. void show_cards( void )  /* Show all the cards. */
  90.   {
  91.     int i;
  92.     for (i=0; i<56; i++)
  93.       show_a_card( i );
  94.   }
  95.  
  96. void bubble_sort_and_show( void )
  97.   {
  98.     CardID_t tmp;
  99.     int i,j;
  100.  
  101.     for (j=0 ;j<56; j++)
  102.       for (i=0; i<55; i++)
  103.         if ( cards[i] > cards[i+1] )  /* CardID_t's can be compared. */
  104.           {
  105.             tmp = cards[i];
  106.                   cards[i] = cards[i+1];
  107.                              cards[i+1] = tmp;
  108.             show_a_card( i );
  109.             show_a_card( i+1);
  110.             WaitTOF();
  111.             WaitTOF();   /* Slow it down enough to see the swaps! */
  112.           }
  113.   }
  114.  
  115. main()
  116.   {
  117.    IntuitionBase = (struct IntuitionBase *)
  118.       OpenLibrary("intuition.library",(long)INTUITION_REV);
  119.    if(IntuitionBase == NULL)
  120.       exit(FALSE);
  121.  
  122.    GfxBase = (struct GfxBase *)
  123.       OpenLibrary("graphics.library",(long)GRAPHICS_REV);
  124.    if(GfxBase == NULL)
  125.       exit(FALSE);
  126.  
  127.    if(( Window = (struct Window *) OpenWindow(&newwindow)) == NULL)
  128.       exit(FALSE);
  129.  
  130.    /* RangeRand() uses RangeSeed.  We need to set RangeSeed to something  */
  131.    /* different each time we run.  Here's one way to do it...     */
  132.  
  133.    CurrentTime( &RangeSeed, &RangeSeed );
  134.  
  135.    if ( CardRange( &cards[ 0], 52, sizeof(cards[0]), SUIT_SPADES,  1 ) &&   /* Normal cards  */
  136.         CardRange( &cards[52],  4, sizeof(cards[0]), SUIT_SPECIAL, 1 )    ) /* Special cards */
  137.      {
  138.        show_cards();
  139.        SetWindowTitles( Window," Here are the cards!","Testing Horizontal Cards");
  140.        Delay( 250 );
  141.  
  142.        Shuffle( cards, 56, sizeof(cards[0]) );
  143.        show_cards();
  144.        SetWindowTitles( Window," The Cards are Shuffled.", (UBYTE *)0xffffffff);
  145.        Delay( 250 );
  146.  
  147.        SetWindowTitles( Window," Let's sort them with a Bubble sort.",(UBYTE *)0xffffffff);
  148.        bubble_sort_and_show();
  149.  
  150.        SetWindowTitles( Window,"<--Close me, I'm done.",(UBYTE *)0xffffffff);
  151.      }
  152.  
  153.     Wait(1L << Window->UserPort->mp_SigBit);
  154.     clear_cards();
  155.     CloseWindow (                   Window        );
  156.     CloseLibrary( (struct Library *)IntuitionBase );
  157.     CloseLibrary( (struct Library *)GfxBase       );
  158.  
  159.     return 0;
  160.   }
  161.